package com.thermal.thermal_inspection.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.data.redis.core.ValueOperations;

@Component
public class RedisUtil {

    @Autowired
    @Qualifier("redisTemplate1") // 指定注入的具体 Bean
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private ValueOperations<String, String> valueOperations;

    // 存储数据到Redis中，并设置过期时间（单位：秒）
    public void set(String key, String value, long timeout) {
        valueOperations.set(key, value, timeout);
    }

    // 从Redis中获取数据
    public String get(String key) {
        return valueOperations.get(key);
    }

    // 删除Redis中的数据
    public void delete(String key) {
        redisTemplate.delete(key);
    }

    // 判断Redis中是否存在某个key
    public boolean exists(String key) {
        return redisTemplate.hasKey(key);
    }
}
